package com.zp.datax.controller;

import com.zp.datax.core.model.DataxJobInfo;
import com.zp.datax.core.result.ReturnT;
import com.zp.datax.service.DataxJobInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author xuxueli 2018-11-21
 */
@Controller
@RequestMapping("/jobinfo")
public class DataxJobInfoController {

    @Resource
    private DataxJobInfoService jobInfoService;


    @RequestMapping("")
    public String index(Model model) {
        return "jobinfo/jobinfo.index";
    }

    @RequestMapping("/pageList")
    @ResponseBody
    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int start,
                                        @RequestParam(required = false, defaultValue = "10") int length,
                                        String name) {
        return jobInfoService.pageList(start, length, name);
    }

    @RequestMapping("/remove")
    @ResponseBody
    public ReturnT<String> remove(Integer sysId) {
        return jobInfoService.remove(sysId);
    }

    @RequestMapping("/modify")
    @ResponseBody
    public ReturnT<String> modify(DataxJobInfo dataxJobInfo) {
        return jobInfoService.update(dataxJobInfo);
    }

    @RequestMapping("/add")
    @ResponseBody
    public ReturnT<String> add(DataxJobInfo dataxJobInfo) {
        return jobInfoService.add(dataxJobInfo);
    }

    @RequestMapping("/trigger")
    @ResponseBody
    public ReturnT<String> trigger(Integer sysId, String params) {
        return jobInfoService.exec(sysId, params);
    }

    @RequestMapping("/stop")
    @ResponseBody
    public ReturnT<String> stop(Integer sysId) {
        return jobInfoService.stop(sysId);
    }

    @RequestMapping("/start")
    @ResponseBody
    public ReturnT<String> start(Integer sysId) {
        return jobInfoService.start(sysId);
    }


}
